<template>
	<view>
		<cu-custom bgColor="bg-red" :isBack="true">		<block slot="backText"></block>
			<block slot="content">我的消息</block>
		</cu-custom>
		<view>
			<scroll-view scroll-y :style="list.length == 0 ? 'height:900px;' : 'height:'+scrollHeight+'px'"  @scrolltolower="getMore">
			<block v-for="(item, index) in list">
				<view class="text-gray text-center margin-top">{{$common.timeFormat(item.created_at)}}</view>
				<view class="margin-lr margin-top-sm bg-white text-center padding radius" @tap="goLink(item, index)">
					<view v-if="!item.notifyMember" class="cu-tag bg-red radius margin-right-xs"></view>{{item.title}}
				</view>
			</block>
			<block v-if="list.length == 0">
					<text style="color: #ffffff;">暂无数据</text>
			</block>
			<view v-else class="cu-load margin-center text-white" :class="loading?'loading':'over'"></view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				list: [],
				hasMore: true,
				loading: false,
				page: 1,
				scrollHeight:900,
			}
		},
		onLoad(options) {
			this.getRemind()
		},
		onShow() {},
		methods: {
			getMore() {
				this.getRemind()
			},
			getRemind() {
				if (!this.loading && this.hasMore) {
					this.$http
						.get('notice_index', {
							type: 2,
							page: this.page
						})
						.then((response) => {
							let list = this.list
							if (response.data.data.length > 0) {
								if (list.length > 0)
									list = list.concat(response.data.data)
								else list = response.data.data
								this.list = list
							} else {
								this.hasMore = false
							}
							this.page += 1
							this.loading = false
						})
						.catch((response) => {
							console.log(response)
							this.loading = false
						})
				}
			},
			goLink(item) {
				this.$http
					.get('notice_index', null, null, item.id)
					.then((response) => {
						this.list[index].notifyMember = 1
					})
					.catch((response) => {})
				if (item.action == 'order') {
					uni.navigateTo({
						url: '/pages/shop/order/detail?id=' + item.map_id
					})
				}else if (item.action == 'wholesale') {
					uni.navigateTo({
						url: '/pages/shop/marketing/wholesale?id=' + item.map_id
					})
				}
			},
			getDetail() {
				this.$http
					.get('notice_index', null, null, this.id)
					.then((response) => {
						this.detail = response.data.data
					})
					.catch((response) => {
						console.log(response)
					})
			}
		},
		onReachBottom() {
			this.getList()
		},
	}
</script>

<style>
</style>
